unit SampleOneTests;
interface
uses MLC.UnitTestFramework, DUnitX.StringUtils;

type

[TestFixture('NewTests.Sprint5')]
[Description('Banana banana banana')]
TSampleOneFixture = class
  protected
    Assert: IAssert;

  public
    [Test(False)]
    [Description('Banana banana')]
     procedure TestOne;

    [Test]
    [TestCase('Test 2a','IntegerParam="1"')]
    [TestCase('Test 2b','IntegerParam="77"')]
     procedure TestTwo( IntegerParam: integer);

    [Test]
    [Ignore('For some reason.')]
     procedure IgnoreMe;

    [Test]
    [TestCase('TripleTest - pie case','A="Blueberry pie" B="2014-01-21T14:00:00"')]
    [TestCase('TripleTest - 1<2 case','A="1 is < 2"   B="2014-01-21T14:00:00"')]
    [Repeats(3)]
     procedure DoThreeTimes( const A: string; B: TDateTime);

    [Test]
    [IgnoreMemoryLeaks]
     procedure Leaky;

    [Setup]    procedure DenotedSetup;
    [TearDown] procedure DenotedTearDown;
    [FixtureSetup] constructor Create;

    destructor Destroy; override;

    [DataDrivenTest]
      function TestsDrivenFromASpreadsheet: IDataDrivenTestCaseCursor;

    [DataDrivenTest]
      function AnotherForm: TDataLoopDriver;

  published
    procedure Setup;
    procedure TearDown;
  end;

implementation
















function TSampleOneFixture.AnotherForm: TDataLoopDriver;
begin
result := procedure ( TestBed: TObject; var More: boolean)
  var
    Bed: TSampleOneFixture;
  begin
  Bed  := TestBed as TSampleOneFixture;
  More := False;
  Bed.Assert.Warn( 'Data not ready');
  Bed.Assert.Pass
  end
end;

constructor TSampleOneFixture.Create;
begin
end;

procedure TSampleOneFixture.DenotedSetup;
begin
end;

procedure TSampleOneFixture.DenotedTearDown;
begin
end;

destructor TSampleOneFixture.Destroy;
begin
inherited;
end;

procedure TSampleOneFixture.DoThreeTimes( const A: string; B: TDateTime);
begin                                   // A="Blueberry pie" B="2014-01-21T14:00:00"
Assert.AreEqual( A, 'Blueberry pie')
end;


procedure TSampleOneFixture.IgnoreMe;
begin
Assert.Fail('I should be ignored')
end;

procedure TSampleOneFixture.Leaky;
var
  P: ^integer;
begin
New( P);  // Deliberate leak
Assert.Pass
end;

procedure TSampleOneFixture.Setup;
begin
end;

procedure TSampleOneFixture.TearDown;
begin
end;

procedure TSampleOneFixture.TestOne;
begin
Assert.IsTrue( True, 'TestOne works')
end;

type
TCursor = class( TDataDrivenTestCaseCursor, IInterface)
  private
     X: integer;
  protected
    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;
    function  PrerunLoadEstimate: integer;             override;
    procedure TestLineItem( TestBed: TObject);         override;
    function  Next: boolean;                           override;
  end;

function TSampleOneFixture.TestsDrivenFromASpreadsheet: IDataDrivenTestCaseCursor;
begin
result := TCursor.Create
end;

procedure TSampleOneFixture.TestTwo( IntegerParam: integer);
begin
Assert.AreEqual( IntegerParam, 77)
end;


function TCursor.Next: boolean;
begin
result := X < PrerunLoadEstimate;
if result then Inc( X)
end;

function TCursor.PrerunLoadEstimate: integer;
begin
result := 2;
end;

procedure TCursor.TestLineItem( TestBed: TObject);
begin
(TestBed as TSampleOneFixture).Assert
  .AreNotEqual( X, 1, 'X should not be One')
end;

function TCursor._AddRef: integer;
begin
result := inherited _AddRef
end;

function TCursor._Release: integer;
begin
result := inherited _Release
end;

end.
